<?php

namespace App\Http\Controllers\User;

use App\Http\Controllers\ApiController;
use App\Http\Controllers\Controller;
use App\User;
use Illuminate\Http\Request;

class RegisterController extends ApiController
{

    //直接使用对象调用时触发invoke方法
    public function __invoke(Request $request, User $user)
    {
        $post = $request->validate([
            'email' => ['sometimes', 'email'],
            'name' => ['required', 'min:3', 'max:50'],
            'password' => ['required', 'min:5', 'confirmed'],
            'mobile' => ['required']
        ], ['name.required' => '昵称不能为空']);
        $user->password = $request->password;
        $user->name = $request->name;
        $user->email = $request->email;
        $user->mobile = $request->mobile;
        $user->save();
        return $user;
    }
}

// //class a{}
// $obj = new a();
// $obj();
